package com.itheima;

import com.itheima.dao.UserDao;
import com.itheima.factory.UserDaoFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 实例工厂初始化bean：
 */
public class  AppForInstanceUser {

    public static void main(String[] args) {
        //创建实例工厂对象
        UserDaoFactory userDaoFactory = new UserDaoFactory();
        //通过实例工厂创建对象
        UserDao userDao = userDaoFactory.getUserDao();

        userDao.save();

        //使用Spring方式来造bean
        ApplicationContext cx = new ClassPathXmlApplicationContext("applicationContext.xml");

        UserDao userDao1 = (UserDao) cx.getBean("userDao");

        userDao1.save();

        UserDao userDao2 = (UserDao) cx.getBean("userDaoFactoryBean");

        userDao2.save();
    }
}
